package com.crazyteam.datasource.dynamic;

import com.crazyteam.datasource.util.TransactionUtil;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import java.util.function.Supplier;

public class TransactionExecutor {

    private PlatformTransactionManager transactionManager;

    public void setTransactionManager(PlatformTransactionManager transactionManager) {
        this.transactionManager = transactionManager;
    }

    public Boolean doTransaction(Supplier<Boolean> supplier){
        return TransactionUtil.doTransaction(this.transactionManager, supplier, new DefaultTransactionDefinition());
    }

    public Boolean doTransaction(Supplier<Boolean> supplier, TransactionDefinition transactionDefinition){
        return TransactionUtil.doTransaction(this.transactionManager, supplier, transactionDefinition);
    }
}
